package com.fanrui.code.chess.mahjong;

import java.util.Date;

import com.fanrui.code.entity.TableLog;
import com.fanrui.code.player.Player;

public class ClubMahjongTable extends PrivateMahjongTable {

	private long clubId;
	
	public ClubMahjongTable(int ID, MahjongRules gameRules, long roomer, long clubId) {
		super(ID, gameRules, roomer);
		this.clubId = clubId;
	}
	
	@Override
	public com.fanrui.proto.cmd.ResJoinMahjongRoom.Result checkEnterCondition(Player player, boolean isReconnect) {
		com.fanrui.proto.cmd.ResJoinMahjongRoom.Result result = super.checkEnterCondition(player, isReconnect);
		if (result == com.fanrui.proto.cmd.ResJoinMahjongRoom.Result.Success) {
			if (player.getFamilyId() != clubId) { // 不允许其他家族的玩家进入
				result = com.fanrui.proto.cmd.ResJoinMahjongRoom.Result.Failed;
			}
		}
		return result;
	}

	public long getClubID() {
		return clubId;
	}

	/**
	 * 俱乐部记录战绩
	 */
	@Override
	protected TableLog createTableLog(long playerId, String playerNickName, String logToken, int income,
			String incomeInfo) {
		TableLog log = new TableLog();
		log.setGameType(this.getGameRules() instanceof GanZhouMahjongRules ? 0 : 1);
		log.setTableId(getID());
		log.setPlayerName(playerNickName);
		log.setLogToken(logToken);
		log.setPlayerId(playerId);
		log.setIncome(income);
		log.setIncomeInfo(incomeInfo);
		log.setInning(roundNum);
		log.setLogTime(new Date());
		log.setClubId((int)clubId);
		return log;
	}
}
